// pages/manpower_resource_edit/manpower_resource_edit.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollTop: 0,
    type: 1,
    employee_id: "",
    name: "",
    sex: "",
    mobile: "",
    card_no: "",
    hardmoney:"",
    goodmoney:"",
    status_name: "",
    status: "",
    time: "",
    isShowStatusList: false,
    statusList: [
      {status:1, name:"在职"},
      {status:2, name:"离职"}
    ],
    sexList: ["保密","男", "女"]
  },

  /**
   * 展示在职状态列表
   */
  showStatusList () {
    if(this.data.type != 1){
      return
    }
    this.setData({
      isShowStatusList: true
    })
  },
  /**
   * 隐藏在职状态列表
   */
  closeStatusList() {
    this.setData({ isShowStatusList: false });
  },

  /**
   * 选择在职状态
   * @param {*} event 
   */
  selectStatus(event) {
    console.log(event.detail);
    this.setData({
      status_name: event.detail.name,
      status: event.detail.status
    })
  },

  // 通过审核
  passVerify(){
    this.setData({
      status: 1
    })

    this.submit();
  },

  // 驳回审核
  returnVerify(){
    this.setData({
      status: 3
    })

    this.submit();
  },
  changefree: function (e) {
    this.setData({
      hardmoney: e.detail
    })
  },
  changebonus: function (e) {
    this.setData({
      goodmoney: e.detail
    })
  },
  submit(){
    let data = {
      hardmoney: this.data.hardmoney,
      goodmoney: this.data.goodmoney,
      employee_id: this.data.employee_id,
      status: this.data.status
    }
    console.log(data)
    wx.$api.submitEmployee(data).then(res=>{
      if(res.data.code == 200){
        wx.navigateTo({
          url: '/pages/manpower_resource/manpower_resource',
        })
      }else{
        wx.$Toast(res.data.msg);
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      type: options.type,
      employee_id: options.id
    })

    wx.$api.detailEmployee({
      employee_id: options.id
    }).then(res=>{
      if(res.data.code == 200){
        let {
          employee_name,
          sex,
          employee_mobile,
          card_no,
          create_time,
          status,
          hardmoney,
          goodmoney,
        } = res.data.data || {}

        this.setData({
          name: employee_name,
          sex: this.data.sexList[sex],
          mobile: employee_mobile,
          card_no: card_no,
          status: status,
          hardmoney: hardmoney,
          goodmoney: goodmoney,
          status_name: status == 0 ? "待审核" : this.data.statusList[status-1].name,
          time: wx.timestamp(create_time*1000, 'day')
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})